package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCDemo6 {
    public static void main(String[] args) {
        try(Connection connection = DBUtil.getConnection()) {
            Statement statement = connection.createStatement();
            String sql = """
                    SELECT c.name,c.floor,t.name,t.title,t.salary
                    FROM class c
                    JOIN teacher t on t.id = c.teacher_id""";
            ResultSet resultSet = statement.executeQuery(sql);
            System.out.println("查询结果如下：");
            System.out.println("班级\t楼层\t老师\t职称\t薪资");
            while (resultSet.next()){
//                String name = resultSet.getString("c.name");
//                int floor = resultSet.getInt("c.floor");
//                String teacherName = resultSet.getString("t.name");
//                String title = resultSet.getString("t.title");
//                double salary = resultSet.getDouble("t.salary");
                String name = resultSet.getString(1);
                int floor = resultSet.getInt(2);
                String teacherName = resultSet.getString(3);
                String title = resultSet.getString(4);
                double salary = resultSet.getDouble(5);
                System.out.println(name+"\t"+floor+"\t"+teacherName+"\t"+title+"\t"+salary);
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
